package com.yc.spring;

import com.yc.spring.bank.bean.Record;
import com.yc.spring.bbs.bean.Board;
import com.yc.spring.bmi.BmiFilter;
import com.yc.spring.bmi.BmiMeasurer;
import com.yc.spring.bmi.Container;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.*;

@Configuration // 等效于 beans.xml
@ComponentScan("com.yc.spring") // 包扫描
@EnableAspectJAutoProxy
public class BeanConfig {
    @Bean("board1") // <bean>
    @Primary  // 主bean
    Board getBoard(){
        return new Board(1,"java",2);
    }


    @Bean // <bean> 没有指定名字，方法名就是id
    @Scope("prototype")
    Board bean2(){
        return new Board(3,"html",4);
    }

    @Bean
    Board parent(){
        Board b = new Board(3,"css",4);
        return b;
    }

    @Bean(autowire = Autowire.BY_NAME)
    Board board(){
        Board b = new Board(3,"js",4);
        return b;
    }

//    @Bean
//    public Container container(){
//        return new Container();
//    }
//
//    @Bean
//    public BmiFilter bmiFilter(){
//        return new BmiFilter();
//    }

    @Bean("a")
    @Primary
    public BmiMeasurer bmiMeasurer(){
        return new BmiMeasurer();
    }

    @Bean
    Record record1(){
        // 匿名类 + 实例块
        return new Record(){{
            this.setId(1234);
        }};
    }

}
